﻿namespace Tw.Trains.Domain
{
    /// <summary> 站点 </summary>
    public class Station
    {
        public string Name { get; }

        public Station(string name)
        {
            Name = name;
        }

        public override bool Equals(object obj)
        {
            if (!(obj is Station))
                return false;

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            var other = (Station)obj;
            var typeOfThis = GetType();
            var typeOfOther = other.GetType();
            if (!typeOfThis.IsAssignableFrom(typeOfOther) && !typeOfOther.IsAssignableFrom(typeOfThis))
            {
                return false;
            }
            return Name.Equals(other.Name);
        }

        public static bool operator ==(Station left, Station right)
        {
            return (Equals(left, null) ? Equals(right, null) : left.Equals(right));
        }

        public static bool operator !=(Station left, Station right)
        {
            return !(left == right);
        }

        protected bool Equals(Station other)
        {
            return other != null && string.Equals(Name, other.Name);
        }

        public override string ToString()
        {
            return Name;
        }

        public override int GetHashCode()
        {
            return Name != null ? Name.GetHashCode() : 0;
        }
    }
}
